package thread.threaddemo;

import java.util.Random;

/**
 * @Author: wenjingyuan
 * @Date: 2022/11/10/17:01
 * @Description:在主线程中自己创建两个线程，两个线程分别创造随机数
 * 在主线程将随机数进行累加
 */
public class ThreadDemo14 {
    static int num1=0;
    static int num2=0;
    public static void main(String[] args) throws InterruptedException {
        Thread t1=new Thread(()->{
         num1=new Random().nextInt(10);
        });
        t1.start();
        Thread t2=new Thread(()->{
            num2=new Random().nextInt(10);
        });
        t2.start();

        t1.join();
        t2.join();
        System.out.println("累加的结果为："+(num1+num2));
    }
}
